package com.monkeysonnet.b2dFluent;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.joints.WheelJoint;
import com.badlogic.gdx.physics.box2d.joints.WheelJointDef;

public class WheelJointFactory extends JointFactory<WheelJointFactory>
{
	private static final WheelJointDef _initialDef = new WheelJointDef();
	
	private WheelJointDef _def;
	
	public WheelJointFactory()
	{
		this(false);
	}
	
	WheelJointFactory(boolean managed)
	{
		super(managed);
		_def = new WheelJointDef();
		setDef(_def);
	}
	
	public WheelJointFactory enableMotor(boolean e)
	{
		_def.enableMotor = e;
		return this;
	}
	
	public WheelJointFactory localAxisA(Vector2 t)
	{
		_def.localAxisA.set(t);
		return this;
	}
	
	public WheelJointFactory localAxisA(float x, float y)
	{
		_def.localAxisA.set(x, y);
		return this;
	}
	
	public WheelJointFactory frequencyHz(float f)
	{
		_def.frequencyHz = f;
		return this;
	}
	
	public WheelJointFactory maxMotorTorque(float t)
	{
		_def.maxMotorTorque = t;
		return this;
	}
	
	public WheelJointFactory motorSpeed(float s)
	{
		_def.motorSpeed = s;
		return this;
	}
	
	public WheelJointFactory localAnchorA (Vector2 v)
	{
		_def.localAnchorA.set(v);
		return this;
	}
	
	public WheelJointFactory localAnchorA (float x, float y)
	{
		_def.localAnchorA.set(x, y);
		return this;
	}
	
	public WheelJointFactory localAnchorB (Vector2 v)
	{
		_def.localAnchorB.set(v);
		return this;
	}
	
	public WheelJointFactory localAnchorB (float x, float y)
	{
		_def.localAnchorB.set(x, y);
		return this;
	}

	public WheelJointFactory dampingRatio(float r)
	{
		_def.dampingRatio = r;
		return this;
	}
	
	public WheelJoint create(World w)
	{
		return (WheelJoint)w.createJoint(_def);
	}
	
	void clear()
	{
		super.clear(_initialDef);
		_def.dampingRatio = _initialDef.dampingRatio;
		_def.enableMotor = _initialDef.enableMotor;
		_def.frequencyHz = _initialDef.frequencyHz;
		_def.localAnchorA.set(_initialDef.localAnchorA);
		_def.localAnchorB.set(_initialDef.localAnchorB);
		_def.localAxisA.set(_initialDef.localAxisA);
		_def.maxMotorTorque = _initialDef.maxMotorTorque;
		_def.motorSpeed = _initialDef.motorSpeed;
	}

	@Override
	public void free()
	{
		B2d.free(this);
	}
}
